<?php

class AppController extends Controller
{
	public $layout='admin';
	private $top = null;
	public $needRightActions = array('*'=>true);
	
	/*
	public function init()
	{
		$menu = new Menu();
		$this->assign('mainMenu',$menu->getMenu());
		$menu_index = $menu->current_menu();
		$this->assign('menu_index',$menu_index);
		$this->assign('subMenu',$menu->getSubMenu($menu_index['menu']));
		$this->assign('menu',$menu);
		$nav_act = Req::get('act')==null?$this->defaultAction:Req::get('act');
		$nav_act = preg_replace("/(_edit)$/", "_list", $nav_act);
		$this->assign('nav_link','/'.Req::get('con').'/'.$nav_act);
		$this->assign('node_index',$menu->currentNode());
		$this->safebox = Safebox::getInstance();
		$this->assign('manager',$this->safebox->get('manager'));
		
		$currentNode = $menu->currentNode();
        if(isset($currentNode['name']))$this->assign('admin_title',$currentNode['name']);
	}
	public function noRight(){
		$this->redirect("/admin/noright");
	}
	*/
	
	public function init()
	{
		
		$menu = new Menu();
		$this->assign('mainMenu',$menu->getMenu());
		$menu_index = $menu->current_menu();
		$this->assign('menu_index',$menu_index);
		$this->assign('subMenu',$menu->getSubMenu($menu_index['menu']));
		$this->assign('menu',$menu);
		$nav_act = Req::get('act')==null?$this->defaultAction:Req::get('act');
		$nav_act = preg_replace("/(_edit)$/", "_list", $nav_act);
		$this->assign('nav_link','/'.Req::get('con').'/'.$nav_act);
		$this->assign('node_index',$menu->currentNode());
		$this->safebox = Safebox::getInstance();
		$this->assign('manager',$this->safebox->get('manager'));
		
		$currentNode = $menu->currentNode();
        if(isset($currentNode['name']))$this->assign('admin_title',$currentNode['name']);
        
        $config = Config::getInstance();
        $domain = $config->get('domain');
        $this->assign("domain", $domain);
        $this->assign("my_app_root", MY_APP_ROOT);
        
	}

	public function noRight(){

		$this->redirect("admin/noright");

	}
	
	
	
	public function version_list()
	{		
		$model = new Model("version");
		$list=$model->select();
		
		$this->assign("list", $list);
		$this->redirect("version_list");
	}
	
	
	public function version_edit()
	{
		$id=Req::args("id");
		if(empty($id))
		{
			$model = new Model("version");
			$maxVersionCode=$model->query("select max(version_code) as max_version_code from qc_version");
			//$this->maxVersionCode=$maxVersionCode[0]['max_version_code'];
			$obj=array();
			$obj['version_code']=$maxVersionCode[0]['max_version_code']+1;
			$this->assign("obj", $obj);
		}
		else 
		{
			$model = new Model("version");
			$id=Req::args("id");
			$obj=$model->where("id=".$id)->find();
			
			$this->obj=$obj;
		}
		$this->redirect();
	}
	
//	public function version_add()
//	{
//		$model = new Model("version");
//		$maxVersionCode=$model->query("select max(version_code) as max_version_code from qc_version");
//		$this->maxVersionCode=$maxVersionCode[0]['max_version_code'];
//		$this->redirect();
//	}
	//获取后缀名
	function get_extension($file)
	{
		return substr($file, strrpos($file, '.')+1);
	}
	
	public function version_save()
	{
		$model = new Model("version");
		$id=Req::args("id");
		if(empty($id))
		{
			//添加保存
			$data['sys_type']='android';
			$data['version_code']=Req::args("version_code");
			$data['version_no']=Req::args("version_no");
			$data['now_update']=Req::args("now_update");
			$data['create_time']=date('Y-m-d H:i:s',time());
			$data['introduct']=Filter::text(Req::args("introduct"));
			
			//上传文件
		
			if(is_uploaded_file($_FILES['upApp']['tmp_name']))
			{
				$upfile=$_FILES['upApp'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
				$arr=explode(".", $yname);
				$firstname=substr(md5($arr[0].time()),0,20);
				$yname = $firstname.".".$arr[1];//重命名文件名
				
				$type=$upfile['type'];
				if($type !== "application/octet-stream" || $this->get_extension($yname) !== "apk")
				{
					$this->redirect("version_list",false,array('msg'=> array('error',"上传类型不正确")));
					die;
				}
				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/app/$yname"))
				{
					$msg = array('error',"上传app文件失败 ");
					$this->redirect("version_list",false,array('msg'=> $msg));
					die;
				}
				
				$data['url']="/data/uploads/app/".$yname;//服务器端储存路径
			}
			
			$result = $model->data($data)->insert();
			if($result)
			{
				$msg = array('success',"发布成功 ");
				
			}
			else
			{
				$msg = array('error',"发布失败");
			}
			$this->redirect("version_list",false,array('msg'=> $msg));
		}
		else 
		{
			//编辑保存
			$data['id']=$id;
			$data['version_no']=Req::args("version_no");
			$data['now_update']=Req::args("now_update");
			$data['introduct']=Filter::text(Req::args("introduct"));
			
			//上传文件
			
//			if(is_uploaded_file($_FILES['upApp']['tmp_name']))
//			{
//				$upfile=$_FILES['upApp'];
//				$yname=iconv("utf-8","gb2312",$upfile['name']);
//				
//				$type=$upfile['type'];
//				if($type !== "application/octet-stream" || $this->get_extension($yname) !== "apk")
//				{
//					$this->redirect("version_list",false,array('msg'=> array('error',"上传类型不正确")));
//					die;
//				}
//				
//				$size=$upfile['size'];//上传文件的大小
//				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
//				if(!move_uploaded_file($tmp_name, "./data/uploads/app/".$yname))
//				{
//					$msg = array('error',"上传app文件失败 ");
//					$this->redirect("version_list",false,array('msg'=> $msg));
//					die;
//				}
//				
//				//如果上传成功，则删掉原来的旧文件
//				$obj=$model->where("id=".$id)->find();
//				unlink(iconv("utf-8","gb2312",".".$obj['url']));
//				$data['url']=iconv("gb2312","utf-8","/data/uploads/app/".$upfile['name']);//服务器端储存路径
//			}
			
			$result = $model->save($data);
			if($result)
			{
				$msg = array('success',"编辑成功 ");
				
			}
			else
			{
				$msg = array('error',"编辑失败");
			}
			$this->redirect("version_list",false,array('msg'=> $msg));
		}
		
		
		
		/*
		$model = new Model("version");
		$data['sys_type']='android';
		$data['version_code']=Req::args("version_code");
		$data['version_no']=Req::args("version_no");
		$data['now_update']=Req::args("now_update");
		$data['create_time']=date('Y-m-d H:i:s',time());
		$data['introduct']=Filter::text(Req::args("introduct"));
		
		//上传文件
		
		if(is_uploaded_file($_FILES['upApp']['tmp_name']))
		{
			$upfile=$_FILES['upApp'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
			
			$type=$upfile['type'];
			if($type !== "application/octet-stream" || $this->get_extension($yname) !== "apk")
			{
				$this->redirect("version_list",false,array('msg'=> array('error',"上传类型不正确")));
				die;
			}
			
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/app/$yname"))
			{
				$msg = array('error',"上传app文件失败 ");
				$this->redirect("version_list",false,array('msg'=> $msg));
				die;
			}
			
			$data['url']="/data/uploads/app/".$upfile['name'];//服务器端储存路径
		}
		
		$result = $model->data($data)->insert();
		if($result)
		{
			$msg = array('success',"发布成功 ");
			
		}
		else
		{
			$msg = array('error',"发布失败");
		}
		$this->redirect("version_list",false,array('msg'=> $msg));
		*/
	}
	
	/*
	public function version_update()
	{
		$model = new Model("version");
		$id=Req::args("id");
		$data['id']=$id;
		$data['version_no']=Req::args("version_no");
		$data['now_update']=Req::args("now_update");
		$data['introduct']=Filter::text(Req::args("introduct"));
		
		//上传文件
		
		if(is_uploaded_file($_FILES['upApp']['tmp_name']))
		{
			$upfile=$_FILES['upApp'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
			
			$type=$upfile['type'];
			if($type !== "application/octet-stream" || $this->get_extension($yname) !== "apk")
			{
				$this->redirect("version_list",false,array('msg'=> array('error',"上传类型不正确")));
				die;
			}
			
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/app/".$yname))
			{
				$msg = array('error',"上传app文件失败 ");
				$this->redirect("version_list",false,array('msg'=> $msg));
				die;
			}
			
			//如果上传成功，则删掉原来的旧文件
			$obj=$model->where("id=".$id)->find();
			unlink(iconv("utf-8","gb2312",".".$obj['url']));
			$data['url']=iconv("gb2312","utf-8","/data/uploads/app/".$upfile['name']);//服务器端储存路径
		}
		
		$result = $model->save($data);
		if($result)
		{
			$msg = array('success',"编辑成功 ");
			
		}
		else
		{
			$msg = array('error',"编辑失败");
		}
		$this->redirect("version_list",false,array('msg'=> $msg));
	}
	
	*/
	
	
	
	public function version_del()
	{
		$model = new Model("version");
		$id=Req::args("id");
		//如果上传成功，则删掉原来的旧文件
		$obj=$model->where("id=".$id)->find();
		unlink(iconv("utf-8","gb2312",".".$obj['url']));
		
		$result=$model->where("id=".$id)->delete();
		if($result)
		{
			$msg = array('success',"删除成功 ");
		}
		else
		{
			$msg = array('error',"删除失败 ");
		}
		$this->redirect("version_list",false,array('msg'=> $msg));
	}
	
	
	/**
	 * APP推广管理
	 * Enter description here ...
	 */
	public function tuiadmin_list()
	{
		$model=new Model("tui");
		$list=$model->select();
		$this->list=$list;
		$this->redirect("tuiadmin_list");
	}
	
    //推广信息编辑
	public function tuiadmin_edit()
	{
		$config=Config::getInstance();
		//将用户设置的值保存到数据库
		$config->set("domain", Req::args("domain"));
		
		$model=new Model("tui");
		$id=Req::args("id");
		
		//$arr['url']='/index.php?con=appreg&act=reg';//需要根据开发情况变动
		$arr['url']='/tip.php';
		
		$arr['title']=Req::args("title");//标题
		$arr['content']=Req::args("content");//内容
		
		$result=$model->data($arr)->where("id=".$id)->update();
		Log::op($this->manager['id'],"编辑推广信息","管理员[".$this->manager['name']."]:编辑了推广信息  标题".Req::args('title')."内容".Req::args('content'));
		$msg = array('success',"编辑成功 ");
		$this->redirect("tuiadmin_list",false,array('msg'=>$msg));
	}
	/*
	public function ad_list(){
		$parse_type = array('1'=>'普通广告','2'=>'多图轮播','3'=>'文字','4'=>'悬浮','5'=>'代码','6'=>'APP端引导页','7'=>'APP端多图轮播','8'=>'APP端商品类别');
		$this->assign("parse_type",$parse_type);
		$this->redirect();
	}
	*/
	//引导页列表
	public function guide_list()
	{
		$model = new Model();
		$list=$model->table("ad as a")->where("type=6")->order("a.order desc")->select();
		//Common::getImgPathByGContent($list[0]['content']);
		$this->assign("list", $list);
		$this->redirect();
	}
	public function guide_edit()
	{
		$id=Req::args("id");
		$model = new Model();
		if(empty($id))
		{
			
		}
		else
		{
			$obj=$model->table("ad")->where("id=".$id)->find();
			//print_r($obj);die;
			$this->assign("obj", $obj);
		}
		$this->redirect();
	}
	
	private $imgType1=array("image/jpeg", "image/png", "image/gif", "image/bmp");
	private $imgType2=array("jpg","png","gif","bmp");
	
	//引导页添加图片
	public function guide_save()
	{
		$id=Req::args("id");
		$model = new Model();
		if(empty($id))
		{
			//上传图片
			if(is_uploaded_file($_FILES['upImg']['tmp_name']))
			{
				$upfile=$_FILES['upImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
//				$arr=explode(".", $yname);
//				$firstname=substr(md5($arr[0].time()),0,20);
//				$yname = $firstname.".".$arr[1];//重命名文件名
				
				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;
				
				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("guide_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
					//die;
				}
				//die;
	//			if($type !== "application/octet-stream" || $this->get_extension($yname) !== "apk")
	//			{
	//				$this->redirect("version_list",false,array('msg'=> array('error',"上传类型不正确")));
	//				die;
	//			}
				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传引导页图片失败 ");
					$this->redirect("version_list",false,array('msg'=> $msg));
					die;
				}
				
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
			}
			
			//顺序
			$data['order']=intval(Req::args("order"));
			$data['is_open']=Req::args("is_open");
			$data['type']='6';
			
			$result=$model->table("ad")->data($data)->insert();
			if($result)
			{
				$this->redirect("guide_list",false,array('msg'=> array('success',"添加引导页广告成功")));
			}
			else 
			{
				$this->redirect("guide_list",false,array('msg'=> array('error',"添加引导页广告失败")));
			}
		}
		else
		{
			$data['order']=Req::args("order");
			$data['is_open']=Req::args("is_open");
			
			$result=$model->table("ad")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("guide_list",false,array('msg'=> array('success',"编辑引导页广告成功")));
			}
			else 
			{
				$this->redirect("guide_list",false,array('msg'=> array('error',"编辑引导页广告失败")));
			}
		}
		
	}
	/**
	 * 删除引导页
	 * Enter description here ...
	 */
	public function guide_del()
	{
		$id=Req::args("id");
		$model = new Model();
		$obj=$model->table("ad")->where("id=".$id)->find();
		$result = $model->table("ad")->where("id=".$id)->delete();
		if($result)
		{
			if(!empty($obj['content']))
			{
				unlink(".".$obj['content']);
			}
			$this->redirect("guide_list",false,array('msg'=> array('success',"删除引导页广告成功")));
		}
		else 
		{
			$this->redirect("guide_list",false,array('msg'=> array('error',"删除引导页广告失败")));
		}
		
	}
	
	//幻灯片列表
	public function slide_list()
	{
		$model = new Model();
		$list=$model->table("ad as a")->where("type=7")->order("a.order desc")->select();
		$this->assign("list", $list);
		$this->redirect();
	}
	
	public function first_slide_list()
	{
		$model = new Model();
		$list=$model->table("app_ad")->where("status=0")->select();
		
		$this->assign("list", $list);
		$this->redirect();
	}
	
	public function goods_slide_list()
	{
		$model = new Model();
		$list=$model->table("ad as a")->where("type=16")->order("a.order desc")->select();
		$this->assign("list", $list);
		$this->redirect();
	}
	
	//幻灯片编辑或者添加
	public function slide_edit()
	{
		$id=Req::args("id");
		if(!empty($id))
		{
			$model = new Model();
			$obj=$model->table("ad")->where("id=".$id)->find();
			$this->assign("obj", $obj);
		}
		
		$this->redirect();
	}
	
	public function first_slide_edit()
	{
		$id=Req::args("id");
		if(!empty($id))
		{
			$model = new Model();
			$obj=$model->table("app_ad")->where("id=".$id)->find();
			$this->assign("obj", $obj);
		}
		
		$this->redirect();
	}
	
	public function goods_slide_edit()
	{
		$id=Req::args("id");
		if(!empty($id))
		{
			$model = new Model();
			$obj=$model->table("ad")->where("id=".$id)->find();
			$this->assign("obj", $obj);
		}
		
		$this->redirect();
	}
	
	//从其他的控制器里面复制的
	public function radio_goods_select()
	{
		$gid=Req::args('gid');//自己写的
		$this->assign("gid", $gid);//自己写的
		
		$this->layout = "blank";
		$s_type = Req::args("s_type");
		$s_content = Req::args("s_content");
		$selCategory=Req::args("selCategory");
		//echo $selCategory;die;
		
		$where = "1=1";
		if($s_content && $s_content!='')
		{
			if($s_type==1){
				$where = "goods_no = '{$s_content}'";
			}else if($s_type==2) {
				$where = "name like '%{$s_content}%' ";
			}
		}
		else 
		{
			if($s_type == 3)
			{
				$where = "category_id={$selCategory}";
			}
		}
		
//		$model = new Model();
//		$category_list=$model->table("goods_category")->select();
//		$this->category_list=$category_list;
		
		$this->assign("s_type",$s_type);
		$this->assign("s_content",$s_content);
		$id = Req::args('id');
		if(!$id  || $id=='') $id = 0;
		$this->assign('id',$id);
		$this->assign("where",$where);
		$this->redirect();
		
	}
	
	
	public function radio_news_select()
	{
		/*
		$gid=Req::args('gid');//自己写的
		
		$this->assign("gid", $gid);//自己写的
		
		$this->layout = "";
		//$s_type = Req::args("s_type");
		//$s_content = Req::args("s_content");
		
		//$this->assign("s_type",$s_type);
		//$this->assign("s_content",$s_content);
		//$id = Req::args('id');
		//if(!$id  || $id=='') $id = 0;
		//$this->assign('id',$id);
		$this->redirect();
		*/
		$gid=Req::args('gid');//自己写的
		$this->assign("gid", $gid);//自己写的
		
		$this->layout = "blank";
		$s_type = Req::args("s_type");
		$s_content = Req::args("s_content");
		$selCategory=Req::args("selCategory");
		//echo $selCategory;die;
		
		$where = "1=1";
		if($s_content && $s_content!='')
		{
			if($s_type==1){
				$where = "goods_no = '{$s_content}'";
			}else if($s_type==2) {
				$where = "name like '%{$s_content}%' ";
			}
		}
		else 
		{
			if($s_type == 3)
			{
				$where = "category_id={$selCategory}";
			}
		}
		
//		$model = new Model();
//		$category_list=$model->table("goods_category")->select();
//		$this->category_list=$category_list;
		
		$this->assign("s_type",$s_type);
		$this->assign("s_content",$s_content);
		$id = Req::args('id');
		if(!$id  || $id=='') $id = 0;
		$this->assign('id',$id);
		$this->assign("where",$where);
		$this->redirect();
		
	}
	
	
	//获取后缀名(已经存在了，重复了)
//	protected function get_extension($file)
//	{
//		return substr($file, strrpos($file, '.')+1);
//	}
	//获取文件名
	protected function get_filename($file)
	{
		return substr($file, 0, strrpos($file,'.'));
	}
	
	//幻灯片添加/编辑
	public function slide_save()
	{
		$id=Req::args("id");
		$model = new Model();
		if(empty($id))
		{
			//上传图片
			if(is_uploaded_file($_FILES['upImg']['tmp_name']))
			{
				$upfile=$_FILES['upImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);	

				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;

				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("slide_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传幻灯片图片失败 ");
					$this->redirect("slide_list",false,array('msg'=> $msg));
					die;
				}
				
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
			}
			
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			$data['type']='7';
			$result=$model->table("ad")->data($data)->insert();
			if($result)
			{
				$this->redirect("slide_list",true,array('msg'=> array('success',"添加幻灯片成功")));
			}
			else
			{
				$this->redirect("slide_list",true,array('msg'=> array('error',"添加幻灯片失败")));
			}
		}
		else
		{
			//上传替换的图片
			if(is_uploaded_file($_FILES['upsImg']['tmp_name']))
			{
				$upfile=$_FILES['upsImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
//				$arr=explode(".", $yname);
//				$firstname=substr(md5($arr[0].time()),0,20);
//				$yname = $firstname.".".$arr[1];//重命名文件名
				
				
				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;
				
				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("slide_list",false,array('msg'=> array('warning',"上传类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("slide_list",false,array('msg'=> $msg));
					die;
				}
				//删除被替换掉的图片
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
				$obj=$model->table("ad")->where("id=".$id)->find();
				unlink(".".$obj['content']);
			}
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			
			$result=$model->table("ad")->where("id=".$id)->data($data)->update();
			if($result)
			{
				
				$this->redirect("slide_list",false,array('msg'=> array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("slide_list",false,array('msg'=> array('warning',"编辑失败")));
			}
		}
		
	}
	
	
	
	
	public function first_slide_save()
	{
		$id=Req::args("id");
		
		$model = new Model();
		$data['type'] = intval(Req::args('sel_type'));
		if(empty($id))
		{
			//上传图片
			if(is_uploaded_file($_FILES['upImg']['tmp_name']))
			{
				$upfile=$_FILES['upImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);	

				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;

				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("first_slide_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("first_slide_list",false,array('msg'=> $msg));
					die;
				}
				$obj = $model->table("app_ad")->where("type=".$data['type']." and status=0")->find();
				if(!empty($obj))
				{
				    $arr = unserialize($obj['content']);
				}
				
				$arr[] = "/data/uploads/ad/".$yname;
				$data['content']=serialize($arr);//服务器端储存路径
			}
			
			/*
			$data['order']=Req::args("order");
			//$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			$data['type']=15;
			*/
			
			
			
			
			if(!empty($obj))
			{
			    //$result=$model->table("app_ad")->data($data)->where("type=".$data['type'])->update();
			    $result=$model->table("app_ad")->data($data)->where("id=".$obj['id'])->update();
			}
			else
			{
			    $result=$model->table("app_ad")->data($data)->insert();
			}
			
			if($result)
			{
				$this->redirect("first_slide_list",true,array('msg'=> array('success',"添加幻灯片成功")));
			}
			else
			{
				$this->redirect("first_slide_list",true,array('msg'=> array('error',"添加幻灯片失败")));
			}
		}
		else
		{
			//上传替换的图片
			if(is_uploaded_file($_FILES['upsImg']['tmp_name']))
			{
				$upfile=$_FILES['upsImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
//				$arr=explode(".", $yname);
//				$firstname=substr(md5($arr[0].time()),0,20);
//				$yname = $firstname.".".$arr[1];//重命名文件名
				
				
				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;
				
				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("first_slide_list",false,array('msg'=> array('warning',"上传类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("first_slide_list",false,array('msg'=> $msg));
					die;
				}
				//删除被替换掉的图片
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
				$obj=$model->table("app_ad")->where("id=".$id)->find();
				unlink(".".$obj['content']);
			}
			/*
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			*/
			
			$result=$model->table("app_ad")->where("id=".$id)->data($data)->update();
			if($result)
			{
				
				$this->redirect("first_slide_list",false,array('msg'=> array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("first_slide_list",false,array('msg'=> array('warning',"编辑失败")));
			}
		}
		
	}
	
	
	
	
	
	
	
	public function goods_slide_save()
	{
		$id=Req::args("id");
		$seller_id = Req::args('seller_id');
		$model = new Model();
		if(empty($id))
		{
			//上传图片
			if(is_uploaded_file($_FILES['upImg']['tmp_name']))
			{
				$upfile=$_FILES['upImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);	

				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;

				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("slide_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("goods_slide_list",false,array('msg'=> $msg));
					die;
				}
				
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
			}
			
			$data['order']=Req::args("order");
			//$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			$data['type']=16;
			
			
			
			//print_r($data);die;
			$data['seller_id'] = $seller_id;
			$result=$model->table("ad")->data($data)->insert();
			if($result)
			{
				$this->redirect("goods_slide_list",true,array('msg'=> array('success',"操作成功")));
			}
			else
			{
				$this->redirect("goods_slide_list",true,array('msg'=> array('error',"操作失败")));
			}
		}
		else
		{
			//上传替换的图片
			if(is_uploaded_file($_FILES['upsImg']['tmp_name']))
			{
				$upfile=$_FILES['upsImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
//				$arr=explode(".", $yname);
//				$firstname=substr(md5($arr[0].time()),0,20);
//				$yname = $firstname.".".$arr[1];//重命名文件名
				
				
				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;
				
				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("goods_slide_list",false,array('msg'=> array('warning',"上传类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("goods_slide_list",false,array('msg'=> $msg));
					die;
				}
				//删除被替换掉的图片
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
				$obj=$model->table("ad")->where("id=".$id)->find();
				unlink(".".$obj['content']);
			}
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			$data['seller_id'] = $seller_id;
			$result=$model->table("ad")->where("id=".$id)->data($data)->update();
			if($result)
			{
				
				$this->redirect("goods_slide_list",false,array('msg'=> array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("goods_slide_list",false,array('msg'=> array('warning',"编辑失败")));
			}
		}
		
	}
	
	
	
	
	
	
	
	
	/**
	 * 删除幻灯片
	 * Enter description here ...
	 */
	public function slide_del()
	{
		
		$id=Req::args("id");
		$model = new Model();
		$obj=$model->table("ad")->where("id=".$id)->find();
		
		$result=$model->where("id=".$id)->delete();
		if($result)
		{
			if(!empty($obj['content']))
			{
				unlink(".".$obj['content']);
			}
			$this->redirect("slide_list",true,array('msg'=> array('success',"删除幻灯片成功")));
		}
		else 
		{
			$this->redirect("slide_list",true,array('msg'=> array('error',"删除幻灯片失败")));
		}
		
	}
	
	
	public function first_slide_del()
	{
		
		$id=Req::args("id");
		$model = new Model();
		$obj=$model->table("app_ad")->where("id=".$id)->find();
		
		$result=$model->where("id=".$id)->delete();
		if($result)
		{
		    /*
			if(!empty($obj['content']))
			{
			    $arr = unserialize($obj['content']);
			    for($i=0; $i<count($arr); $i++)
			    {
			        unlink( APP_ROOT.$arr[$i] );
			    }				
			}
			*/
			$this->redirect("first_slide_list",true,array('msg'=> array('success',"操作成功")));
		}
		else 
		{
			$this->redirect("first_slide_list",true,array('msg'=> array('error',"操作失败")));
		}
		
	}
	
	
	
	public function goods_slide_del()
	{
		$id=Req::args("id");
		$model = new Model();
		$obj=$model->table("ad")->where("id=".$id)->find();
		
		$result=$model->where("id=".$id)->delete();
		if($result)
		{
			if(!empty($obj['content']))
			{
			    $new_path = substr($obj['content'],1);
			    
				unlink( APP_ROOT.$new_path );
			}
			$this->redirect("goods_slide_list",true,array('msg'=> array('success',"删除幻灯片成功")));
		}
		else 
		{
			$this->redirect("goods_slide_list",true,array('msg'=> array('error',"删除幻灯片失败")));
		}
		
	}
	
	
	public function ad_del()
	{
		$model = new Model();
		$category_id = intval( Req::args('category_id') );
		$goods_id = intval( Req::args('goods_id') );
		
		//echo $category_id." ".$goods_id;die;
		
		$app_ad_obj = $model->table("app_ad")->where("category_id=".$category_id)->find();
		$content = $app_ad_obj['content'];
		if(strstr($content, ",{$goods_id},"))
		{
			$new_content = str_replace("{$goods_id},", "",$content);
			$result = $model->table("app_ad")->data(array('content'=>$new_content))->where("category_id=".$category_id)->update();
			if( $result )
			{
				$this->redirect("category_list",true,array('msg'=> array('success',"操作成功")));
			}
			else
			{
				$this->redirect("category_list",true,array('msg'=> array('error',"操作失败")));
			}
		}
		else
		{
			$this->redirect("category_list",true,array('msg'=> array('error',"操作失败")));
		}
	}
	
	//分类广告
	public function category_list()
	{
		$model = new Model();
		
		$list = $model->table("app_ad")->select();
		for($i=0,$c=count($list); $i<$c; $i++)
		{
			$demo = array();
			$content = $list[$i]['content'];
			$arr = explode(",",$content);
			
			for($j=0; $j<count($arr); $j++)
			{
				if(!empty($arr[$j]) && $arr[$j]>0)
				{
					
					$goods_id = $arr[$j];
					
					$goods_obj = Common::getGoodsInfo($goods_id);
					
					$data['img'] = $goods_obj['img'];
					$data['name'] = $goods_obj['name'];
					$data['goods_id'] = $goods_id;
					$demo[] = $data;
				}
			}
			$list[$i]['goods_list']= $demo;
		}
		
		$this->assign("list", $list);
		
		$this->redirect();
	}
	
	public function getGoodsListByClassifyId()
	{
	
		$cid = Req::args('category_id');
		$list = Common::getGoodsListByClassifyId( $cid );
		echo Common::_toJSON($list);
	}
	
	public function category_ad_edit()
	{
		$id = intval( Req::args("id") );
		/*
		$dp_id = intval( Req::args("dp_id") );
		
		$model = new Model();
		
		$obj=$model->table("app_ad")->where("id=$id")->find();
		
		$this->assign("obj", $obj);
		$this->assign("dp_id", $dp_id);
		
		$category_id = $obj['category_id'];
		
		$seller_list = Common::get_seller_by_category_id($category_id);
		
		$this->assign('seller_list', $seller_list);
		*/
		
		$this->redirect();
	}
	
	public function first_goods_ad_list()
	{
		$model = new Model();
		$list=$model->table("ad as a")->where("id=150")->select();
		for($i=0; $i<count($list); $i++)
		{
			$list[$i]['content']=unserialize($list[$i]['content']);
		}
		//print_r($list);die;
		$this->list=$list;
		$this->redirect();
	}
	
	
	
	public function wulong_ad_save()
	{
		$id = Req::args("id");
		$ad_model = new Model("ad");
		$type = Req::args("type");
		if($type === "edit")
		{
			//上传替换的图片
			$imgArr=$_FILES['upsImg'];
			
			$index = Req::args("index");//获取索引
			$co='';
			$obj=$ad_model->where("id=".$id)->find();
			
			$content=unserialize($obj['content']);
			
			if(!empty($imgArr))
			{
				foreach($imgArr['error'] as $key=>$error)
				{
					if($error ==UPLOAD_ERR_OK)
					{
						$temp_name = iconv("utf-8","gb2312",$imgArr['tmp_name'][$key]);
						$file_name = iconv("utf-8","gb2312", $imgArr['name'][$key]);
						
						$type = $imgArr['type'][$key];
//						$arr=explode(".", $file_name);
						$ext=$this->get_extension($file_name);//扩展名
						$file_name=$this->get_filename($file_name);//文件名
						$file_name=substr(md5($file_name.time().rand()),0,20).".".$ext;
						
						if(!in_array($type, $this->imgType1))
						{
							$this->redirect("wulong_ad_list",false,array('msg'=> array('warning',"上传类型不正确")));
						}
						
						if(!move_uploaded_file($temp_name, "./data/uploads/ad/$file_name"))
						{
							$msg = array('error',"上传图片失败2");
							$this->redirect("wulong_ad_list",true,array('msg'=> $msg));
						}
						unlink(".".$content[$index]['path']);
						$co="/data/uploads/ad/$file_name";
						$content[$index]["path"]=$co;
					}
				}
			}
			$content[$index]['link'] = Req::args("link1");
			$data['content']=serialize($content);
			
			$result=$ad_model->data($data)->where("id=".$id)->update();
			if($result)
			{
				$msg = array('success',"编辑首页广告成功 ");
				$this->redirect("wulong_ad_list",false,array('msg'=> $msg));
			}
			else 
			{
				$msg = array('error',"编辑首页广告失败 ");
				$this->redirect("wulong_ad_list",false,array('msg'=> $msg));
			}
		}
		else
		{
			
			//上传替换的图片
			$imgArr=$_FILES['upsImg'];
			$co='';
			$obj=$ad_model->where("id=".$id)->find();
			$content=unserialize($obj['content']);
			
			if(!empty($imgArr))
			{
				foreach($imgArr['error'] as $key=>$error)
				{
					if($error ==UPLOAD_ERR_OK)
					{
						$temp_name = iconv("utf-8","gb2312",$imgArr['tmp_name'][$key]);
						$file_name = iconv("utf-8","gb2312", $imgArr['name'][$key]);
						
						$type = $imgArr['type'][$key];
//						$arr=explode(".", $file_name);
						$ext=$this->get_extension($file_name);//扩展名
						$file_name=$this->get_filename($file_name);//文件名
						$file_name=substr(md5($file_name.time().rand(1,100000)),0,20).".".$ext;
						
						if(!in_array($type, $this->imgType1))
						{
							$this->redirect("wulong_ad_list",false,array('msg'=> array('warning',"上传类型不正确")));
						}
						
						if(!move_uploaded_file($temp_name, "./data/uploads/ad/$file_name"))
						{
							$msg = array('error',"上传图片失败2");
							$this->redirect("wulong_ad_list",true,array('msg'=> $msg));
						}
						//unlink(".".$content[$index]['path']);
						$co="/data/uploads/ad/$file_name";
						
					}
				}
			}
			if(empty($content))
			{
				$content[0]["path"]=$co;
				$content[0]['link'] = Req::args("link1");
			}
			else 
			{
				$length = count($content);
				$content[$length]["path"]=$co;
				$content[$length]['link'] = Req::args("link1");
			}
			//print_r($content);die;
			//print_r($content);die;
			$data['content']=serialize($content);
			
			$result=$ad_model->table("ad")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$msg = array('success',"添加广告成功 ");
			}
			else 
			{
				$msg = array('error',"添加广告失败 ");
			}
			$this->redirect("wulong_ad_list", false, $msg);
		}
	}
	
	
	public function wl_ad_edit()
	{
		$id = Req::args("id");
		$index = Req::args("index");
		$type = Req::args("type");
		$model = new Model();
		$obj = $model->table("ad")->where("id=".$id)->find();
		
		$this->assign("name", $obj['name']);
		if($type === "edit")
		{
			$arr = unserialize($obj['content']);
			$arr = $arr[$index];
			$arr['id'] = $id;
			$this->assign("title","编辑广告");	
			$this->assign("index", $index);
			$this->assign("obj", $arr);
		}
		else 
		{
			$this->assign("id", $id);
			$this->assign("title","添加广告");
		}
		$this->assign("type", $type);
		$this->redirect();
	}
	
	
	public function fg_ad_edit()
	{
		$id = Req::args("id");
		$index = Req::args("index");
		$type = Req::args("type");
		$model = new Model();
		$obj = $model->table("ad")->where("id=".$id)->find();
		
		$this->assign("name", $obj['name']);
		if($type === "edit")
		{
			$arr = unserialize($obj['content']);
			$arr = $arr[$index];
			$arr['id'] = $id;
			$this->assign("title","编辑广告");	
			$this->assign("index", $index);
			$this->assign("obj", $arr);
		}
		else 
		{
			$this->assign("id", $id);
			$this->assign("title","添加广告");
		}
		$this->assign("type", $type);
		$this->redirect();
	}
	
	public function first_goods_ad_save()
	{
		$id = Req::args("id");
		$ad_model = new Model("ad");
		$type = strval(Req::args("type"));
		if($type === "edit")
		{
			//上传替换的图片
			$imgArr=$_FILES['upsImg'];
			
			$index = Req::args("index");//获取索引
			$co='';
			$obj=$ad_model->where("id=".$id)->find();
			
			$content=unserialize($obj['content']);
			
			if(!empty($imgArr))
			{
				foreach($imgArr['error'] as $key=>$error)
				{
					if($error ==UPLOAD_ERR_OK)
					{
						$temp_name = iconv("utf-8","gb2312",$imgArr['tmp_name'][$key]);
						$file_name = iconv("utf-8","gb2312", $imgArr['name'][$key]);
						
						$type = $imgArr['type'][$key];
//						$arr=explode(".", $file_name);
						$ext=$this->get_extension($file_name);//扩展名
						$file_name=$this->get_filename($file_name);//文件名
						$file_name=substr(md5($file_name.time().rand()),0,20).".".$ext;
						
						if(!in_array($type, $this->imgType1))
						{
							$this->redirect("first_goods_ad_list",false,array('msg'=> array('warning',"上传类型不正确")));
						}
						
						if(!move_uploaded_file($temp_name, "./data/uploads/ad/$file_name"))
						{
							$msg = array('error',"上传图片失败2");
							$this->redirect("first_goods_ad_list",true,array('msg'=> $msg));
						}
						unlink(".".$content[$index]['path']);
						$co="/data/uploads/ad/$file_name";
						$content[$index]["path"]=$co;
					}
				}
			}
			$content[$index]['link'] = Req::args("link1");
			$data['content']=serialize($content);
			
			$result=$ad_model->data($data)->where("id=".$id)->update();
			if($result)
			{
				$msg = array('success',"编辑首页广告成功 ");
				$this->redirect("first_goods_ad_list",false,array('msg'=> $msg));
			}
			else 
			{
				$msg = array('error',"编辑首页广告失败 ");
				$this->redirect("first_goods_ad_list",false,array('msg'=> $msg));
			}
		}
		else
		{
			
			//上传替换的图片
			$imgArr=$_FILES['upsImg'];
			$co='';
			$obj=$ad_model->where("id=".$id)->find();
			$content=unserialize($obj['content']);
			//print_r($content);die;
			
			if(!empty($imgArr))
			{
				foreach($imgArr['error'] as $key=>$error)
				{
					if($error ==UPLOAD_ERR_OK)
					{
						$temp_name = iconv("utf-8","gb2312",$imgArr['tmp_name'][$key]);
						$file_name = iconv("utf-8","gb2312", $imgArr['name'][$key]);
						
						$type = $imgArr['type'][$key];
//						$arr=explode(".", $file_name);
						$ext=$this->get_extension($file_name);//扩展名
						$file_name=$this->get_filename($file_name);//文件名
						$file_name=substr(md5($file_name.time().rand(1,100000)),0,20).".".$ext;
						
						if(!in_array($type, $this->imgType1))
						{
							$this->redirect("first_goods_ad_list",false,array('msg'=> array('warning',"上传类型不正确")));
						}
						
						if(!move_uploaded_file($temp_name, "./data/uploads/ad/$file_name"))
						{
							$msg = array('error',"上传图片失败2");
							$this->redirect("first_goods_ad_list",true,array('msg'=> $msg));
						}
						//unlink(".".$content[$index]['path']);
						$co="/data/uploads/ad/$file_name";
						
					}
				}
			}
			if(empty($content))
			{
				$content[0]["path"]=$co;
				$content[0]['link'] = Req::args("link1");
			}
			else 
			{
				$length = count($content);
				$content[$length]["path"]=$co;
				$content[$length]['link'] = Req::args("link1");
			}
			//print_r($content);die;
			//print_r($content);die;
			$data['content']=serialize($content);
			
			$result=$ad_model->table("ad")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$msg = array('success',"添加广告成功 ");
			}
			else 
			{
				$msg = array('error',"添加广告失败 ");
			}
			$this->redirect("first_goods_ad_list", false, $msg);
		}
	}
	
	
	
	public static function get_all_seller()
	{
		$model = new Model();
		$result = $model->query("select zyk_user.*,zyk_dp.category_id from zyk_user,zyk_dp where zyk_user.u_lx=2 and zyk_user.id=zyk_dp.user_id");
		return $result;
		
	}
	
	public function get_seller_by_category_id()
	{
		$id = Req::args("category_id");
		$model = new Model();
		//$resutl = $model->query("select zyk_user.*,zyk_dp.did,zyk_dp.category_id,zyk_dp.dp_name from zyk_user,zyk_dp where zyk_user.u_lx=2 and zyk_user.id=zyk_dp.user_id and zyk_dp.category_id=$category_id");
		$result = $model->table("dp")->where("category_id=$id")->select();
		
		echo Json::_toJSON($result);
	}
	
	//分类广告编辑/添加
	public function category_edit()
	{		
	    
	    $id = intval( Req::args("id") );
	    if( !empty($id) )
	    {
	        $model = new Model();
	        $my_ad_obj = $model->table("app_ad")->where("id=$id")->find();
	        $content = $my_ad_obj['content'];
	        $arr = explode(',', $content);
	        $glist = [];
	        for($i=0,$c=count($arr); $i<$c; $i++)
	        {
	            $goods_obj = Common::getGoodsInfo($arr[$i]);
	            $glist[] = $goods_obj;
	        }
	         
	        $this->assign('glist', $glist);
	        $this->assign("my_ad_obj", $my_ad_obj);
	    }
	    $this->redirect();
	    
	    /*
		$id=Req::args("id");
		$ad_model = new Model("ad");
		$model = new Model();
		//$category_list=$model->table("goods_category")->select();
		//$this->category_list=$category_list;
		if(!empty($id))
		{
			$this->assign("title","编辑首页广告");
			$obj=$ad_model->where("id=".$id)->find();
			
//			$arr=unserialize($obj['content']);
//			for($i=0; $i<count($arr); $i++)
//			{
//				$obj['paths'][$i]=$arr[$i]['path'];
//				$obj['links'][$i]=$arr[$i]['link'];
//			}
			$this->assign("obj", $obj);
		}
		else 
		{
			$this->assign("title","添加首页广告");
		}
		
		$all_seller_list = self::get_all_seller();
		
//		$this->assign("all_seller_list", $all_seller_list);
		
		$this->redirect();
		*/
	}
	
	
	public function ad_save()
	{
		$id = Req::args("id");
		
		$model = new Model();
		if(empty($id))
		{
			$title = Req::args("title");
			$order = Req::args("order");
			$is_open = Req::args("is_open");
			$data['name'] = $title;
			$data['order'] = $order;
			$data['type'] = 1;
			$data['is_open'] = $is_open;
			$result = $model->table("app_ad")->data($data)->insert();
			if($result)
			{
				$msg = array("success", "添加成功");
			}
			else
			{
				$msg = array("error", "添加失败");
			}
			
		}
		else 
		{
			$id = Req::args("id");
			$data['name'] = Req::args("title");
			
			$data['order'] = Req::args("order");
			$data['is_open'] = Req::args("is_open");
			//$result = $model->query("update qc_ad set name='{$name}',order=$order,is_open=$is_open where id=$id");
			$result = $model->table("app_ad")->data($data)->where("id=$id")->update();
			if($result)
			{
				$msg = array("success", "编辑成功");
			}
			else 
			{
				$msg = array("error", "编辑失败");
			}
		}
		$this->redirect("category_list", true, array('msg'=> $msg));
	}
	
	
	//分类广告添加/编辑保存
	public function category_save()
	{
	    
	    $name        = Req::args('name');
	    $type        = Req::args('sel_type');//位置：0首页 1品牌商城 2积分商城
	    $ad_order    = Req::args('ad_order');//顺序
	    $category_id = Req::args('sel_category');//大类别id
	    $hid_sel_str = Req::args('hid_sel_str');
	    $id          = Req::args('id');
	    $model       = new Model();
	    $data['name']= $name;
	    $data['type']= $type;
	    $data['ad_order'] =$ad_order;
	    $data['category_id'] = $category_id;
	    $data['content']     = $hid_sel_str;
	    $data['status']      = 1;//0轮播  1分类广告
	    
	    if(empty($id))
	    {
	        $res = $model->table("app_ad")->data( $data )->insert();
	    }
	    else
	    {
	        $res = $model->table("app_ad")->data( $data )->where("id=$id")->update();
	    }
	    if($res)
	    {
	        $msg = array('success',"操作成功");
	    }
	    else
	    {
	        $msg = array('fail',"操作失败 ");
	    }
	    $this->redirect("category_list",true,array('msg'=> $msg));
	    
	    /*
		$model = new Model();
		
		$id = intval( Req::args("id") );
		if(empty($id))
		{
		    $name = trim(Filter::sql(Req::args('name')));
			$category_id = intval(Req::args('sel_category'));
			$goods_id = intval( Req::args('sel_goods') );
			$ad_order = intval( Req::args('ad_order') );
			$app_ad_obj = $model->table("app_ad")->where("category_id=$category_id")->find();
			if( empty( $app_ad_obj ) )
			{
			    $data['name']  = $name;
				$data['category_id'] = $category_id;
				$data['content'] = ",{$goods_id},";
				$data['ad_order']= $ad_order;
				$result = $model->table("app_ad")->data($data)->insert();
				if($result)
				{
					$msg = array('success',"操作成功");
				}
				else 
				{
					$msg = array('error',"操作失败");
				}
				
				$this->redirect("category_list", true, array('msg'=> $msg));
				die;
			}
			else
			{
			    $data['name'] = $name;
				$content = $app_ad_obj['content'];
				if(strstr($content,",{$goods_id},"))
				{
					$msg = array('error',"该商品已存在于该类别中,请不要重复操作");
					$this->redirect("category_list", true, array('msg'=> $msg));
					die;
				}
				else
				{
					$data['content'] = $content."{$goods_id},";
					$result = $model->table("app_ad")->data($data)->where("category_id=".$category_id)->update();
					if( $result )
					{
						$msg = array('success',"操作成功");
					}
					else
					{
						$msg = array('error',"操作失败");
					}
					$this->redirect("category_list", true, array('msg'=> $msg));
					die;
				}
			}
		}
		else
		{
		}
		*/
	}
	
	
	public function category_del()
	{
		$id=Req::args("id");
		$model = new Model();
		
		$result=$model->table("app_ad")->where("id=".$id)->delete();
		if($result)
		{
			$msg = array('success',"操作成功 ");
		}
		else
		{
			$msg = array('error',"操作失败 ");
		}
		$this->redirect("category_list",true,array('msg'=> $msg));
	}
	
	public function category_del_c()
	{
	    $id = Req::args("id");
	    $gid = Req::args("gid");
	    $model = new Model();
	    $obj = $model->table("app_ad")->where("id=$id")->find();
	    $content = $obj['content'];
	    $arr = explode(",", $content);
	    foreach($arr as $k=>$v)
	    {
	        if($gid == $v)
	        {
	            unset($arr[$k]);
	        }
	    }
	    sort($arr);
	    $str = implode(",", $arr);
	    $res = $model->table("app_ad")->data(['content'=>$str])->where("id=$id")->update();
	    if($res)
	    {
	        $msg = array('success',"操作成功");
	    }
	    else
	    {
	        $msg = array('fail',"操作失败 ");
	    }
	    $this->redirect("category_list",true,array('msg'=> $msg));
	}
	
	
	
	
	public function ad_edit()
	{
		$id = Req::args("id");
		$index = Req::args("index");
		$type = Req::args("type");
		$model = new Model();
		$obj = $model->table("app_ad")->where("id=".$id)->find();
		
		$this->assign("name", $obj['name']);
		if($type === "edit")
		{
			$arr = unserialize($obj['content']);
			$arr = $arr[$index];
			$arr['id'] = $id;
			$this->assign("title","编辑广告");	
			$this->assign("index", $index);
			$this->assign("obj", $arr);
		}
		else 
		{
			$this->assign("id", $id);
			$this->assign("title","添加广告");
		}
		$this->assign("type", $type);
		$this->redirect();
	}
	
	
	
	public function wl_del_ad()
	{
		$id = Req::args("id");
		$index = Req::args("index");
		$model = new Model();
		$obj = $model->table("ad")->where("id=".$id)->find();
		
		$arr = unserialize($obj['content']);
		unset($arr[$index]);
		sort($arr);
		
		$data['content'] = serialize($arr);
		
		$result = $model->table("ad")->data($data)->where("id=".$id)->update();
		if($result)
		{
			$msg = array('success','删除成功');
		}
		else 
		{
			$msg = array('error','删除失败');
		}
		
		$this->redirect("wulong_ad_list",false,array('msg'=>$msg));
	}
	
	public function fg_del_ad()
	{
		$id = Req::args("id");
		$index = Req::args("index");
		$model = new Model();
		$obj = $model->table("ad")->where("id=".$id)->find();
		
		$arr = unserialize($obj['content']);
		unset($arr[$index]);
		sort($arr);
		
		$data['content'] = serialize($arr);
		
		$result = $model->table("ad")->data($data)->where("id=".$id)->update();
		if($result)
		{
			$msg = array('success','删除成功');
		}
		else 
		{
			$msg = array('error','删除失败');
		}
		
		$this->redirect("first_goods_ad_list",false,array('msg'=>$msg));
	}
	
	
	public function del_ad()
	{
		$id = Req::args("id");
		$index = Req::args("index");
		$model = new Model();
		$obj = $model->table("app_ad")->where("id=".$id)->find();
		
		$arr = unserialize($obj['content']);
		unset($arr[$index]);
		//ksort($arr);
		$arr=array_values($arr);
		
		$data['content'] = serialize($arr);
		
		$result = $model->table("app_ad")->data($data)->where("id=".$id)->update();
		if($result)
		{
			$msg = array('success','删除成功');
		}
		else 
		{
			$msg = array('error','删除失败');
		}
		
		$this->redirect("category_list",false,array('msg'=>$msg));
	}
	
	//公司简介
	public function gsjj_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=1")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	public function gsjj_edit()
	{
		$model = new Model();
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gsjj_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gsjj_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=1;
		$result = $model->table("appdoc")->data($data)->where("type=1")->update();
		if($result)
		{
			$this->redirect("gsjj_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("gsjj_list",true,array('msg'=>array('warning',"编辑失败")));
		}
		
	}
	
	//新闻资讯列表
	public function news_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=2")->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function news_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] = 2;
		
		//print_r($data);die;
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("news_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("news_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			$data['create_time'] = date("Y-m-d H:i:s",time());
			//添加
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("news_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("news_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("news_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("news_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	public function news_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function news_del()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			$this->redirect("news_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("news_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	public function gudong_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=3")->order("sort desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function gudong_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function gudong_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] = 3;
		
		$data['sort'] = Req::post("sort");
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gudong_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gudong_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			//添加
			$data['create_time'] = date("Y-m-d H:i:s",time());
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("gudong_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("gudong_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("gudong_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("gudong_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	public function gudong_del()
	{
		$id = intval(Req::get("id"));
		
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			unlink("./".$obj['img']);
			$this->redirect("gudong_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("gudong_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	
	
	public function taiji_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=4")->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function taiji_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function taiji_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] = 4;
		
		//$data['sort'] = Req::post("sort");
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("taiji_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("taiji_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			//添加
			$data['create_time'] = date("Y-m-d H:i:s",time());
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("taiji_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("taiji_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("taiji_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("taiji_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	public function taiji_del()
	{
		$id = intval(Req::get("id"));
		
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			unlink("./".$obj['img']);
			$this->redirect("taiji_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("taiji_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	
	
	public function taijiinfo_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=10")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	/**
	 * 太极舞龙俱乐部简介信息修改
	 * Enter description here ...
	 */
	public function taijiinfo_edit()
	{
		$model = new Model();
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("taijiinfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("taijiinfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(is_uploaded_file($_FILES['titleImg']['tmp_name']))
		{
			$upfile=$_FILES['titleImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gxltinfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gxltinfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['title_img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		
		
		
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=10;
		$result = $model->table("appdoc")->data($data)->where("type=10")->update();
		if($result)
		{
			$this->redirect("taijiinfo_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("taijiinfo_list",true,array('msg'=>array('warning',"编辑失败")));
		}
		
	}
	
	
	
	
	
	
	
	public function tiannian_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=5")->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function tiannian_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function tiannian_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] =5;
		
		//$data['sort'] = Req::post("sort");
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("tiannian_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("tiannian_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			//添加
			$data['create_time'] = date("Y-m-d H:i:s",time());
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("tiannian_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("tiannian_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("tiannian_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("tiannian_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	public function tiannian_del()
	{
		$id = intval(Req::get("id"));
		
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			unlink("./".$obj['img']);
			$this->redirect("tiannian_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("tiannian_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	
	public function tiannianinfo_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=11")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	/**
	 * 天年值友俱乐部简介信息修改
	 * Enter description here ...
	 */
	public function tiannianinfo_edit()
	{
		$model = new Model();
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("tiannianinfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("tiannianinfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		
		if(is_uploaded_file($_FILES['titleImg']['tmp_name']))
		{
			$upfile=$_FILES['titleImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gxltinfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gxltinfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['title_img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=11;
		$result = $model->table("appdoc")->data($data)->where("type=11")->update();
		if($result)
		{
			$this->redirect("tiannianinfo_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("tiannianinfo_list",true,array('msg'=>array('warning',"编辑失败")));
		}
		
	}
	
	
	
	
	
	
	
	public function zhiqing_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=6")->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function zhiqing_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function zhiqing_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] =6;
		
		//$data['sort'] = Req::post("sort");
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("zhiqing_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("zhiqing_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			//添加
			$data['create_time'] = date("Y-m-d H:i:s",time());
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("zhiqing_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("zhiqing_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("zhiqing_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("zhiqing_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	public function zhiqing_del()
	{
		$id = intval(Req::get("id"));
		
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			unlink("./".$obj['img']);
			$this->redirect("zhiqing_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("zhiqing_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	
	
	
	public function zhiqinginfo_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=12")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	/**
	 * 知青俱乐部简介信息修改
	 * Enter description here ...
	 */
	public function zhiqinginfo_edit()
	{
		$model = new Model();
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("zhiqinginfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("zhiqinginfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(is_uploaded_file($_FILES['titleImg']['tmp_name']))
		{
			$upfile=$_FILES['titleImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("zhiqinginfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("zhiqinginfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['title_img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		
		
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=12;
		$result = $model->table("appdoc")->data($data)->where("type=12")->update();
		if($result)
		{
			$this->redirect("zhiqinginfo_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("zhiqinginfo_list",true,array('msg'=>array('warning',"编辑失败")));
		}
		
	}
	
	
	
	//企业文化
	public function qiye_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=7")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	
	
	public function qiye_edit()
	{
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=7;
		$result = $model->table("appdoc")->data($data)->where("type=7")->update();
		if($result)
		{
			$this->redirect("qiye_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("qiye_list",true,array('msg'=>array('warning',"编辑失败")));
		}
	}
	
	public function zzyl_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=19")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	public function zzyl_edit()
	{
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=19;
		$result = $model->table("appdoc")->data($data)->where("type=19")->update();
		if($result)
		{
			$this->redirect("zzyl_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("zzyl_list",true,array('msg'=>array('warning',"编辑失败")));
		}
	}
	
	
	public function userleave_list()
	{
		$model = new Model();
		$list = $model->table('leave')->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function userleave_del()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$result = $model->table("leave")->where("id=".$id)->delete();
		if($result)
		{
			$this->redirect("userleave_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("userleave_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	
	
	
	
	
	
	function doc_save()
	{
		$model = new Model();
		$id = intval(Req::args("id"));
		$data['title'] = Filter::sql(Req::args("title"));
		$data['category_id'] = intval(Req::args("category_id"));
		$data['content'] = Filter::text(Req::args("content"));
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("doc_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("doc_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(!empty($id))
		{
			$res = $model->table("app_article")->data($data)->where("id={$id}")->update();
			if($res)
			{
				$this->redirect("doc_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("doc_list",true,array('msg'=>array('error',"编辑失败")));
			}
		}
		else 
		{
			$data['publish_time'] = date("Y-m-d H:i:s", time());
				
			$result = $model->table("app_article")->data($data)->insert();
			if($result)
			{
				$this->redirect("doc_list",true,array('msg'=>array('success',"添加成功")));
			}
			else 
			{
				$this->redirect("doc_list",true,array('msg'=>array('error',"添加失败")));
			}	
		}
		
		/*
		$rules = array('title:required:标题不能为空!','content:required:内容不能为空！');
		$info = Validator::check($rules);
		if($info==true) {
			Filter::form(array('sql'=>'title','text'=>'content'));
			if(Req::args('id')==null)Req::args('publish_time',date('Y-m-d H:i:s'));
			$id = Req::args('id');
			$model = new Model("app_article");
			
			if($id){
				$model->where("id=$id")->update();
				Log::op($this->manager['id'],"修改文章","管理员[".$this->manager['name']."]:修改了文章 ".Req::args('title'));
			}else{
				$model->insert();
				Log::op($this->manager['id'],"添加文章","管理员[".$this->manager['name']."]:添加了文章 ".Req::args('title'));
			}
		}else if(is_array($info)){
			$data = Req::args()+array('validator'=>$info);
			$this->redirect('doc_edit',false,$data);
			exit;
		}
		$this->redirect("doc_list");
		*/
	}

	//删除文章
	public function doc_del()
	{
		$id = Req::args('id');
		if(is_array($id)){
			for($i=0;$i<count($id); $i++)
			{
				if($id[$i]==40 || $id[$i]==41 || $id[$i]==38|| $id[$i]==35 || $id[$i]==33 || $id[$i]==34)
				{
					$msg = array('error',"无法删除");
					$this->redirect("doc_list",false,array('msg'=> $msg));
					die;
				}
			}
			$ids = implode(',', $id);
		}
		else
		{
			$ids = $id;
			if($id==40 || $id==41 || $id==38|| $id==35 || $id==33 || $id==34)
			{
				$msg = array('error',"无法删除");
				$this->redirect("doc_list",false,array('msg'=> $msg));
				die;
			}
		}
		$model = new Model("app_article");
		$articles = $model->where("id in ($ids)")->findAll();
		$str = '';
		foreach ($articles as $article) {
			$str .= $article['title'].'、';
		}
		$str = trim($str,'、');
		$model->where("id in ($ids)")->delete();
		if($articles){
			Log::op($this->manager['id'],"删除文章","管理员[".$this->manager['name']."]:删除了文章 ".$str);
			$msg = array('success',"成功删除文章 ".$str);
			$this->redirect("doc_list",false,array('msg'=> $msg));
		}else{
			$this->redirect("doc_list");
		}
		
	}

	public function doc_type_list()
	{
		$model = new Model('app_category');
		$datas = $model->order('path,sort desc')->findAll();
		$result = Common::treeArray($datas);
		$this->assign("category",$result);
		$this->redirect();
	}
	
	public function doc_edit()
	{
		$id = Req::args("id");
		$model = new Model("app_article");
		if(!empty($id))
		{
			$obj = $model->where("id=".$id)->find();
			$this->assign("id", $id);
			$this->assign("title", $obj['title']);
			$this->assign("content", $obj['content']);
			$this->assign("category_id", $obj['category_id']);
			$this->assign("img", $obj['img']);
		}
		$this->redirect();
	}
	
	public function doc_type_edit()
	{
		$id=Req::args("id");
		$model = new Model('app_category');
		if(!empty($id))
		{
			$obj = $model->where("id=".$id)->find();
			//$this->id = $id;
			$this->assign("id", $id);
			//$this->name = $obj['name'];
			$this->assign("name", $obj['name']);
			//$this->alias = $obj['alias'];
			$this->assign("alias", $obj['alias']);
			$this->assign("sort", $obj['sort']);
			$this->assign("path", $obj['path']);
			$this->assign("parent_id", $obj['parent_id']);
		}
		$this->redirect();
	}

	function doc_list()
	{
		$category = new Model('app_category');
		$rows = $category->findAll();
		$categorys = array(0=>'默认分类');
		foreach ($rows as $row) {
			$categorys[$row['id']] = $row['name'];
		}
		$this->categorys = $categorys;
		
		$this->redirect('doc_list');
	}
	
	//文章分类
	function doc_type_save()
	{
		$category = new Model("app_category");
		$name = Req::args("name");
		$alias = Req::args("alias");
		$parent_id = Req::args("parent_id");
		$sort = intval(Req::args("sort"));
		$id = Req::args("id")==null?0:Req::args("id");

		$item = $category->where("id != $id and ((name = '$name' and parent_id =$parent_id ) or alias = '$alias' )")->find();
		if($item){
			if($alias == $item['alias']) $this->msg = array("warning","别名要求唯一,方便url美化,操作失败！");
				else $this->msg = array("error","同一级别下已经在在相同分类！");
				unset($item['id']);
			$this->redirect("doc_type_edit",true,Req::args());
		}else{
			//最得父节点的信息
			$parent_node = $category->where("id = $parent_id")->find();
			$parent_path = "";
			if($parent_node){
				$parent_path = $parent_node['path'];
			}
			$current_node = $category->where("id = $id")->find();
			//更新节点
			if($current_node){
				$current_path = $current_node['path'];
				if(strpos($parent_path, $current_path)===false){

					if($parent_path!='')$new_path = $parent_path.$current_node['id'].",";
					else $new_path = ','.$current_node['id'].',';

					$category->data(array('path'=>"replace(`path`,'$current_path','$new_path')"))->where("path like '$current_path%'")->update();
					$category->data(array('parent_id'=>$parent_id,'id'=>$id,'sort'=>$sort,'name'=>$name,'alias'=>$alias))->update();
					Log::op($this->manager['id'],"修改文章分类","管理员[".$this->manager['name']."]:修改了文章分类 ".Req::args('name'));
					$this->redirect("doc_type_list");
				}else{
					$this->msg = array("warning","此节点不能放到自己的子节点上,操作失败！");
					$this->redirect("doc_type_edit",true,Req::args());
				}
			}
			else{
				//插件节点
				$lastid = $category->insert();
				if($parent_path!='')$new_path = $parent_path."$lastid,";
				else $new_path = ",$lastid,";
				$category->data(array('path'=>"$new_path",'id'=>$lastid,'sort'=>$sort))->update();
				Log::op($this->manager['id'],"添加文章分类","管理员[".$this->manager['name']."]:添加了文章分类 ".Req::args('name'));
				$this->redirect("doc_type_list");
			}
		} 
	}
	//文章分类删除操作
	function doc_type_del(){
		$id = Req::args('id');
		$category = new Model("app_category");
		$child = $category->where("parent_id = $id")->find();
		if($child){
			$this->msg = array("warning","由于存在子分类，此分类不能删除，操作失败！");
			$this->redirect("doc_type_list",false);
		}
		else{
			$article = new Model("app_article");
			$row = $article->where('category_id = '.$id)->find();
			if($row){
				$this->msg = array("warning","此分类下还有文章，无法删除！");
				$this->redirect("doc_type_list",false);
			}else{
				$cate = $category->where("id=$id ")->find();
				$category->where("id=$id")->delete();
				Log::op($this->manager['id'],"删除文章分类","管理员[".$this->manager['name']."]:删除了文章分类 ".$cate['name']);
				$this->redirect("doc_type_list");
			}
		}
	}
	
	
	
	public function userleave_edit()
	{
		$id = intval(Req::args("id"));
		$model = new Model();
		if(!empty($id))
		{
			$obj = $model->table("leave")->where("id=".$id)->find();
			$this->assign("obj", $obj);
			$this->assign("id", $id);
		}
		$this->redirect();
	}
	
	public function userleave_save()
	{
		$id = intval(Req::args("id"));
		$reply_content = Filter::text(Req::args("content"));
		if(empty($reply_content))
		{
			$this->redirect("userleave_list",true,array('msg'=>array('warning',"回复失败，回复内容不能为空")));
		}
		$model = new Model();
		$data['reply_content'] = $reply_content;
		$data['reply_time'] = date("Y-m-d H:i:s",time());
		$result = $model->table("leave")->data($data)->where("id=".$id)->update();
		if($result)
		{
			$this->redirect("userleave_list",true,array('msg'=>array('success',"回复成功")));
		}
		else 
		{
			$this->redirect("userleave_list",true,array('msg'=>array('warning',"回复失败")));
		}
	}
	
	
	public function app_menu_edit()
	{
		$id = intval(Req::args("id"));
		$model = new Model();
		if(!empty($id))
		{
			$obj = $model->table("app_menu")->where("id=".$id)->find();
			$this->assign("obj", $obj);
			$this->assign("id", $id);
		}
		$article_list = $model->table("app_article")->select();
		$menu_one = $model->table("app_menu")->where("parent_id=0")->select();
		$this->assign("menu_one", $menu_one);
		$this->assign("article_list", $article_list);
		
		$this->redirect();
	}
	
	
	
	public function app_menu_save()
	{
		$id = intval(Req::args("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::args("title"));
		/*
		$data['menu_level'] = intval(Req::args("menu_level"));
		
		if($data['menu_level'] === 1)
		{
			$data['parent_id']=0;
		}
		elseif($data['menu_level'] === 2)
		{
			$data['parent_id'] = intval(Req::args("parent_id"));
		}
		$data['mode'] = intval(Req::args("mode"));
		*/
		
		$data['sort'] = intval(Req::args("sort"));
		
		if(!empty($id))
		{
			$mod= intval(Req::args("hid_mode"));
			
			if($mod === 0)
			{
				$data['desc_id'] = intval(Req::args("desc_1"));
			}
			if($mod === 1)
			{
				$data['desc_id'] = intval(Req::args("desc_2"));
			}
			
			
			$result = $model->table("app_menu")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("app_menu_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("app_menu_list",true,array('msg'=>array('error',"编辑失败")));
			}
		}
		else
		{
			$data['menu_level'] = intval(Req::args("menu_level"));
		
			if($data['menu_level'] === 1)
			{
				$data['parent_id']=0;
			}
			elseif($data['menu_level'] === 2)
			{
				$data['parent_id'] = intval(Req::args("parent_id"));
			}
			$data['mode'] = intval(Req::args("mode"));
			if($data['mode'] === 0)
			{
				$data['desc_id'] = intval(Req::args("desc_1"));
			}
			if($mod === 1)
			{
				$data['desc_id'] = intval(Req::args("desc_2"));
			}
			$result =$model->table("app_menu")->data($data)->insert();
			if($result)
			{
				if($data['menu_level'] === 1)
				{
					$d['path'] = ",{$result},";
					$model->table("app_menu")->data($d)->where("id=".$result)->update();
				}
				elseif($data['menu_level'] === 2) 
				{
					$d['path'] = ",".$data['parent_id'].",{$result},";
					$model->table("app_menu")->data($d)->where("id=".$result)->update();
				}
				$this->redirect("app_menu_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("app_menu_list",true,array('msg'=>array('error',"添加失败")));
			}
		}
	}
	
	public function app_menu_del()
	{
		$id= intval(Req::args("id"));
		$model = new Model();
		$list = $model->table("app_menu")->where("parent_id=".$id)->select();
		if(!empty($list))
		{
			$this->redirect("app_menu_list",false,array('msg'=>array('error',"该菜单下面还存在子菜单，无法删除")));
		}
		$result = $model->table("app_menu")->where("id=".$id)->delete();
		if($result)
		{
			$this->redirect("app_menu_list",false,array('msg'=>array('success',"删除成功")));
		}
		else 
		{
			$this->redirect("app_menu_list",false,array('msg'=>array('error',"删除失败")));
		}
	}
	
	
	public function attention_list()
	{
		$model = new Model();
		$list = $model->table("app_attention")->order("sort desc")->select();
		$this->assign("list", $list);
		$this->redirect();
	}
	
	public function attention_edit()
	{
		$id = intval(Req::args("id"));
		$model = new Model();
		$news_list = $model->table("appdoc")->where("type!=7 and type!=10 and type!=11 and type!=12 and type!=1")->select();
		$this->assign("news_list", $news_list);
		if(!empty($id))
		{
			$obj = $model->table("app_attention")->where("id=".$id)->find();
			$this->assign("obj",$obj);
		}
		
		if(empty($id))
		{
			$this->assign("title", "添加关注");
		}
		else 
		{
			$this->assign("title", "编辑关注");
		}
		$this->redirect();
	}
	
	public function attention_del()
	{
		$id = intval(Req::args("id"));
		$model = new Model();
		$result = $model->table("app_attention")->where("id=".$id)->delete();
		if($result)
		{
			$this->redirect("attention_list",false,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("attention_list",false,array('msg'=>array('error',"删除失败")));
		}
	}
	
	public function attention_save()
	{
		$model = new Model();
		$id = Req::args("id");
		$data['news_id']=intval(Req::args("news_id"));
		$data['sort']=intval(Req::args("sort"));
		
		if(empty($id))
		{
			$data['att_time']=date("Y-m-d H:i:s",time());
			$result = $model->table("app_attention")->data($data)->insert();
			if($result)
			{
				$this->redirect("attention_list",false,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("attention_list",false,array('msg'=>array('error',"删除失败")));
			}
		}
		else
		{
			$result = $model->table("app_attention")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("attention_list",false,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("attention_list",false,array('msg'=>array('error',"编辑失败")));
			}
		}
		
	}
	
	/**
	 * 俱乐部报名信息列表
	 * Enter description here ...
	 */
	public function bm_list()
	{
		$model = new Model();
		$list =$model->table("jlbbm")->select();
		$this->assign("list", $list);
		$this->redirect();
	}
	
	public function bm_del()
	{
		$id=intval(Req::args("id"));
		$model = new Model();
		$result =$model->table("jlbbm")->where("id=".$id)->delete();
		if($result)
		{
			$this->redirect("bm_list",false,array('msg'=>array('success',"删除成功")));
		}
		else 
		{
			$this->redirect("bm_list",false,array('msg'=>array('error',"删除失败")));
		}
		
	}
	
	public function gxltinfo_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=13")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	/**
	 * Enter description here ...
	 */
	public function gxltinfo_edit()
	{
		$model = new Model();
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gxltinfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gxltinfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		if(is_uploaded_file($_FILES['titleImg']['tmp_name']))
		{
			$upfile=$_FILES['titleImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gxltinfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gxltinfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['title_img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		
		//$data['type']=13;
		$result = $model->table("appdoc")->data($data)->where("type=13")->update();
		if($result)
		{
			$this->redirect("gxltinfo_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("gxltinfo_list",true,array('msg'=>array('warning',"编辑失败")));
		}
		
	}
	
	
	
	public function gxlt_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=14")->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function gxlt_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function gxlt_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] = 14;
		
		//$data['sort'] = Req::post("sort");
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("gxlt_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("gxlt_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			//添加
			$data['create_time'] = date("Y-m-d H:i:s",time());
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("gxlt_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("gxlt_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("gxlt_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("gxlt_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	public function gxlt_del()
	{
		$id = intval(Req::get("id"));
		
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			unlink("./".$obj['img']);
			$this->redirect("gxlt_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("gxlt_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	
	//行走的家->老年乐游中的图片
	public function lnly_list()
	{
		$model = new Model();
		$list=$model->table("ad as a")->where("type=18")->order("a.order desc")->select();
		$this->assign("list", $list);
		$this->redirect();
	}
	public function lnly_edit()
	{
		$id=Req::args("id");
		if(!empty($id))
		{
			$model = new Model();
			$obj=$model->table("ad")->where("id=".$id)->find();
			$this->assign("obj", $obj);
		}
		
		$this->redirect();
	}
	public function lnly_save()
	{
		$id=Req::args("id");
		$model = new Model();
		if(empty($id))
		{
			//上传图片
			if(is_uploaded_file($_FILES['upImg']['tmp_name']))
			{
				$upfile=$_FILES['upImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);	

				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;

				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("lnly_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传幻灯片图片失败 ");
					$this->redirect("lnly_list",false,array('msg'=> $msg));
					die;
				}
				
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
			}
			
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			$data['type']='18';
			$result=$model->table("ad")->data($data)->insert();
			if($result)
			{
				$this->redirect("lnly_list",true,array('msg'=> array('success',"添加幻灯片成功")));
			}
			else
			{
				$this->redirect("lnly_list",true,array('msg'=> array('error',"添加幻灯片失败")));
			}
		}
		else
		{
			//上传替换的图片
			if(is_uploaded_file($_FILES['upsImg']['tmp_name']))
			{
				$upfile=$_FILES['upsImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
//				$arr=explode(".", $yname);
//				$firstname=substr(md5($arr[0].time()),0,20);
//				$yname = $firstname.".".$arr[1];//重命名文件名
				
				
				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;
				
				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("lnly_list",false,array('msg'=> array('warning',"上传类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("lnly_list",false,array('msg'=> $msg));
					die;
				}
				//删除被替换掉的图片
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
				$obj=$model->table("ad")->where("id=".$id)->find();
				unlink(".".$obj['content']);
			}
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			
			$result=$model->table("ad")->where("id=".$id)->data($data)->update();
			if($result)
			{
				
				$this->redirect("lnly_list",false,array('msg'=> array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("lnly_list",false,array('msg'=> array('warning',"编辑失败")));
			}
		}
	}
	
	public function lnly_del()
	{
		$id = intval(Req::args("id"));
		$model = new Model();
		$result = $model->table("ad")->where("id=".$id)->delete();
		if($result)
		{
			$this->redirect("lnly_list",false,array('msg'=> array('success',"删除成功")));
		}
		else
		{
			$this->redirect("lnly_list",false,array('msg'=> array('warning',"删除失败")));
		}
	}
	
	
	
//行走的家中的轮播图图片
	public function xzdj_list()
	{
		$model = new Model();
		$list=$model->table("ad as a")->where("type=17")->order("a.order desc")->select();
		$this->assign("list", $list);
		$this->redirect();
	}
	public function xzdj_edit()
	{
		$id=Req::args("id");
		if(!empty($id))
		{
			$model = new Model();
			$obj=$model->table("ad")->where("id=".$id)->find();
			$this->assign("obj", $obj);
		}
		
		$this->redirect();
	}
	public function xzdj_save()
	{
		$id=Req::args("id");
		$model = new Model();
		if(empty($id))
		{
			//上传图片
			if(is_uploaded_file($_FILES['upImg']['tmp_name']))
			{
				$upfile=$_FILES['upImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);	

				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;

				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("xzdj_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传幻灯片图片失败 ");
					$this->redirect("xzdj_list",false,array('msg'=> $msg));
					die;
				}
				
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
			}
			
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			$data['type']='17';
			$result=$model->table("ad")->data($data)->insert();
			if($result)
			{
				$this->redirect("xzdj_list",true,array('msg'=> array('success',"添加幻灯片成功")));
			}
			else
			{
				$this->redirect("xzdj_list",true,array('msg'=> array('error',"添加幻灯片失败")));
			}
		}
		else
		{
			//上传替换的图片
			if(is_uploaded_file($_FILES['upsImg']['tmp_name']))
			{
				$upfile=$_FILES['upsImg'];
				$yname=iconv("utf-8","gb2312",$upfile['name']);
				
//				$arr=explode(".", $yname);
//				$firstname=substr(md5($arr[0].time()),0,20);
//				$yname = $firstname.".".$arr[1];//重命名文件名
				
				
				$ext=$this->get_extension($yname);
				$filename=$this->get_filename($yname);
				$firstname=substr(md5($filename.time()),0,20);
				$yname=$firstname.".".$ext;
				
				$type=$upfile['type'];
				if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
				{
					$this->redirect("xzdj_list",false,array('msg'=> array('warning',"上传类型不正确")));
					//die;
				}				
				$size=$upfile['size'];//上传文件的大小
				$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
				{
					$msg = array('error',"上传图片失败 ");
					$this->redirect("xzdj_list",false,array('msg'=> $msg));
					die;
				}
				//删除被替换掉的图片
				$data['content']="/data/uploads/ad/".$yname;//服务器端储存路径
				$obj=$model->table("ad")->where("id=".$id)->find();
				unlink(".".$obj['content']);
			}
			$data['order']=Req::args("order");
			$data['link']=Req::args("link");
			$data['is_open']=Req::args("is_open");
			
			$result=$model->table("ad")->where("id=".$id)->data($data)->update();
			if($result)
			{
				
				$this->redirect("xzdj_list",false,array('msg'=> array('success',"编辑成功")));
			}
			else 
			{
				$this->redirect("xzdj_list",false,array('msg'=> array('warning',"编辑失败")));
			}
		}
	}
	
	public function first_ad_edit()
	{
		
		$t = intval(Req::args("f_type"));//图片的类型
		$sub_type = Req::args("sub_type");//上传类型
		$sys_type = Req::args("sys_type");//手机类型
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
			/*
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
			*/
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("first_ad_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
			
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			
			if(intval($sys_type) === 0)
			{
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/android/$yname"))
				{
					$msg = array('error',"上传引导页图片失败 ");
					$this->redirect("first_ad_list",false,array('msg'=> $msg));
					die;
				}
				$data['content']="/data/uploads/ad/android/".$yname;//服务器端储存路径
			}
			else 
			{
				if(!move_uploaded_file($tmp_name, "./data/uploads/ad/ios/$yname"))
				{
					$msg = array('error',"上传引导页图片失败 ");
					$this->redirect("first_ad_list",false,array('msg'=> $msg));
					die;
				}
				$data['content']="/data/uploads/ad/ios/".$yname;//服务器端储存路径
			}
		}
		
		
		$model = new Model();
		if($sub_type == 'add')
		{
			$data['f_type'] = $t;
			$data['sys_type'] = $sys_type;
			$result = $model->table("fad")->data($data)->insert();
		}
		else
		{
			$o = $model->table("fad")->where("f_type=".$t)->find();
			if(!empty($o))
			{
				$model->table("fad")->where("f_type=".$t)->delete();
			}
			
			
			$data['f_type'] = $t;
			$data['sys_type'] = $sys_type;
			$result = $model->table("fad")->data($data)->insert();
			
			//$result=$model->table("fad")->data($data)->where("f_type=".$t)->update();
		}
		
		
		if($result)
		{
			$this->redirect("first_ad_list",false,array('msg'=> array('success',"操作成功")));
		}
		else 
		{
			$this->redirect("first_ad_list",false,array('msg'=> array('error',"操作失败")));
		}
		
	}
	
	
	public function first_ad_list()
	{
		$model = new Model();
		$android_list = $model->table("fad")->where("sys_type=0")->select();
		
		$ios_list = $model->table("fad")->where("sys_type=1")->select();
		if(!empty($android_list))
		{
			for($i=0;$i<count($android_list); $i++)
			{
				$android_obj[$android_list[$i]['f_type']] = $android_list[$i]['content'];
			
			}
			$this->assign("android_obj", $android_obj);
		}
		
		if(!empty($ios_list))
		{
			for($i=0; $i<count($ios_list); $i++)
			{
				$ios_obj[$ios_list[$i]['f_type']]  = $ios_list[$i]['content'];
			}
			$this->assign("ios_obj", $ios_obj);
		}
		
		//$this->redirect("list", $list);
		$this->redirect();
	}
	
	
	

	//文化中国行
	public function wenhuazginfo_edit()
	{
		$model = new Model();
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("wenhuazginfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("wenhuazginfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(is_uploaded_file($_FILES['titleImg']['tmp_name']))
		{
			$upfile=$_FILES['titleImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("wenhuazginfo_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("wenhuazginfo_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['title_img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		
		
		
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Req::post("content");
		$data['type']=17;
		$result = $model->table("appdoc")->data($data)->where("type=17")->update();
		if($result)
		{
			$this->redirect("wenhuazginfo_list",true,array('msg'=>array('success',"编辑成功")));
		}
		else
		{
			$this->redirect("wenhuazginfo_list",true,array('msg'=>array('warning',"编辑失败")));
		}
		
	}
	
	public function wenhuazginfo_list()
	{
		$model = new Model();
		$gsjj_obj = $model->table("appdoc")->where("type=17")->find();
		$this->assign("obj", $gsjj_obj);
		$this->redirect();
	}
	
	
	public function wenhuazg_edit()
	{
		$id = intval(Req::get("id"));
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		$this->assign("obj",$obj);
		$this->redirect();
	}
	
	public function wenhuazg_save()
	{
		$id = intval(Req::post("id"));
		$model = new Model();
		$data['title'] = Filter::sql(Req::post("title"));
		$data['content'] = Filter::text(Req::post("content"));
		$data['type'] =18;
		
		//$data['sort'] = Req::post("sort");
		
		if(is_uploaded_file($_FILES['upImg']['tmp_name']))
		{
			$upfile=$_FILES['upImg'];
			$yname=iconv("utf-8","gb2312",$upfile['name']);
				
			$ext=$this->get_extension($yname);
			$filename=$this->get_filename($yname);
			$firstname=substr(md5($filename.time()),0,20);
			$yname=$firstname.".".$ext;
				
			$type=$upfile['type'];
			if(!in_array($type, $this->imgType1) || !in_array($this->get_extension($yname), $this->imgType2))
			{
				$this->redirect("wenhuazg_list",false,array('msg'=> array('warning',"上传图片类型不正确")));
			}
				
			$size=$upfile['size'];//上传文件的大小
			$tmp_name=iconv("utf-8","gb2312",$upfile['tmp_name']);
			if(!move_uploaded_file($tmp_name, "./data/uploads/ad/$yname"))
			{
				$msg = array('error',"上传引导页图片失败 ");
				$this->redirect("wenhuazg_list",false,array('msg'=> $msg));
				die;
			}
				
			$data['img']="/data/uploads/ad/".$yname;//服务器端储存路径
		}
		
		if(empty($id))
		{
			//添加
			$data['create_time'] = date("Y-m-d H:i:s",time());
			$result = $model->table("appdoc")->data($data)->insert();
			if($result)
			{
				$this->redirect("wenhuazg_list",true,array('msg'=>array('success',"添加成功")));
			}
			else
			{
				$this->redirect("wenhuazg_list",true,array('msg'=>array('warning',"添加失败")));
			}
		}
		else
		{
			$result = $model->table("appdoc")->data($data)->where("id=".$id)->update();
			if($result)
			{
				$this->redirect("wenhuazg_list",true,array('msg'=>array('success',"编辑成功")));
			}
			else
			{
				$this->redirect("wenhuazg_list",true,array('msg'=>array('warning',"编辑失败")));
			}
		}
	}
	
	
	public function wenhuazg_del()
	{
		$id = intval(Req::get("id"));
		
		$model = new Model();
		$obj = $model->table("appdoc")->where("id=".$id)->find();
		
		$result = $model->table("appdoc")->where("id=".$id)->delete();
		if($result)
		{
			unlink("./".$obj['img']);
			$this->redirect("wenhuazg_list",true,array('msg'=>array('success',"删除成功")));
		}
		else
		{
			$this->redirect("wenhuazg_list",true,array('msg'=>array('warning',"删除失败")));
		}
	}
	public function wenhuazg_list()
	{
		$model = new Model();
		$list = $model->table('appdoc')->where("type=18")->order("create_time desc")->select();
		$this->assign("list",$list);
		$this->redirect();
	}
	
	public function category_ad_del()
	{
		$id = intval( Req::args("id") );
		$dp_id = intval( Req::args("dp_id") );
		$model = new Model();
		$obj = $model->table("app_ad")->where("id=$id")->find();
		if(empty($obj))
		{
			$this->redirect("category_list",true,array('msg'=>array('error',"操作失败")));
		}
		else 
		{
			$dp = unserialize($obj['dp']);
			
			if(count($dp) > 0)
			{
				unset($dp[$dp_id]);
				
				if(count($dp)>0)
				{
					ksort($dp);
					
				}
				$model->table("app_ad")->data( array("dp"=>serialize($dp)))->where("id=$id")->update();
			}
			$this->redirect("category_list",true,array('msg'=>array('success',"操作成功")));
		}
		
		
	}
	
	
	
	
}
?>